from torch.optim import SGD, Adam



class OptimizerFactory:

    optimizers = {'SGD': SGD, 'Adam': Adam}

    @staticmethod
    def build_optimizer(optimizer_cfg):
        cfg = optimizer_cfg.copy()
        optimizer_cls = OptimizerFactory.optimizers[cfg.pop('type')]
        return optimizer_cls(**cfg)


def build_optimizer(optimizer_cfg):
    return OptimizerFactory.build_optimizer(optimizer_cfg)


